package cn.edu.hbpu.common.utils;

import java.util.Calendar;
import java.util.Date;

/**
 * @Author yuwenteng
 * @Date 2017/9/22 22:48
 * @Description 考勤数据中用到的date工具类
 */
public class DateUtils {

    private static Calendar calendar = Calendar.getInstance();

    /**
     * @Author yuwenteng
     * @Date 2017/9/19 11:04
     * @Description 拿到当前日期是星期几
     */
    public static int getCurrentWeek() {
        calendar.setTime(new Date());
        int week = calendar.get(Calendar.DAY_OF_WEEK) - 1;
        if (week == 0) {
            week = 7;
        }
        return week;
    }

    /**
     * @Author yuwenteng
     * @Date 2017/9/19 11:12
     * @Description 计算出出勤时长
     */
    public static int getAbsenceMinute(Date startTime, Date endTime) {
        long start = startTime.getTime();
        long end = endTime.getTime();
        int minute = (int) ((end - start) / (1000 * 60));
        return minute;
    }

    /**
     * @Author yuwenteng
     * @Date 2017/9/19 11:40
     * @Description 获取当天某个时间
     */
    public static Date getDate(int hour, int minute) {
        calendar.set(Calendar.HOUR_OF_DAY, hour);
        calendar.set(Calendar.MINUTE, minute);
        Date date = calendar.getTime();
        System.out.println(date);
        return date;
    }
}
